package com.epichust.bootumpp.controller;

import com.epichust.bootumpp.config.NotIntercept;
import com.epichust.bootumpp.model.bo.ReturnBO;
import com.epichust.bootumpp.model.entity.Mbb5ProduBom;
import com.epichust.bootumpp.service.IMbb5ProduBomService;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author ：pengmin
 * @date ：Created in 2020/12/29
 * @description：产品BOM控制层
 */
@RestController
@RequestMapping("/umpp/Mbb5ProduBom")
public class Mbb5ProduBomController {

    @Autowired
    public IMbb5ProduBomService iMbb5ProduBomService;


    @RequestMapping(value = "/getAllMbb5ProduBom", method = {RequestMethod.POST})
    @NotIntercept
    public String getAllMbb5ProduBom(@RequestBody Map<String,String> map) throws Exception{
        try{
            // 新建返回对象
            Gson gson = new GsonBuilder().serializeNulls().create();
            List<Mbb5ProduBom> list= iMbb5ProduBomService.getAllMbb5ProduBom(map);
            ReturnBO bo = new ReturnBO();
            bo.setState(0);
            bo.setObject(gson.toJson(list));
            return gson.toJson(bo);
        }catch(Exception e){
            e.printStackTrace();
            Gson gson = new GsonBuilder().serializeNulls().create();
            ReturnBO bo = new ReturnBO();
            bo.setState(1);
            bo.setObject("查询失败："+e.getMessage());
            return gson.toJson(bo);
        }
    }
    @RequestMapping(value = "/getAllBom", method = {RequestMethod.POST})
    @NotIntercept
    public String getAllBom(@RequestBody Map<String,String> map) throws Exception{
        try{
            // 新建返回对象
            Gson gson = new GsonBuilder().serializeNulls().create();
            List<Map> list= iMbb5ProduBomService.getAllBom(map);
            ReturnBO bo = new ReturnBO();
            bo.setState(0);
            bo.setObject(gson.toJson(list));
            return gson.toJson(bo);
        }catch(Exception e){
            e.printStackTrace();
            Gson gson = new GsonBuilder().serializeNulls().create();
            ReturnBO bo = new ReturnBO();
            bo.setState(1);
            bo.setObject("查询失败："+e.getMessage());
            return gson.toJson(bo);
        }
    }
    @RequestMapping(value = "/getAllBomByParams", method = {RequestMethod.POST})
    @NotIntercept
    public String getAllBomByParams(@RequestBody Map<String,String> map) throws Exception{
        try{
            // 新建返回对象
            Gson gson = new GsonBuilder().serializeNulls().create();
            List<Mbb5ProduBom> list= iMbb5ProduBomService.getAllBomByParams(map);
            ReturnBO bo = new ReturnBO();
            bo.setState(0);
            bo.setObject(gson.toJson(list));
            return gson.toJson(bo);
        }catch(Exception e){
            e.printStackTrace();
            Gson gson = new GsonBuilder().serializeNulls().create();
            ReturnBO bo = new ReturnBO();
            bo.setState(1);
            bo.setObject("查询失败："+e.getMessage());
            return gson.toJson(bo);
        }
    }

}
